export function toCamelCase(string: string) {
  if (!string) return '';
  return String(string)
    .replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
    .replace(/[^A-Za-z0-9]+/g, '$')
    .replace(/([a-z])([A-Z])/g, (m, a, b) => a + '$' + b)
    .toLowerCase()
    .replace(/(\$)(\w)/g, (m, a, b) => b.toUpperCase());
}

export const isEmpty = (value: any) => {
  return value == null || value === '' ||
    (typeof value === 'string' && value.trim() === '') ||
    (typeof value === 'object' && Object.keys(value).length === 0) ||
    (value instanceof Array && value.length === 0)
};

export const nonEmpty = (value: any) => {
  return !isEmpty(value)
};

export function uuid(len: number) {
  const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  let value: Array<any> = [];
  let i;
  const radix = chars.length;
  if (!len) len = 32;

  for (i = 0; i < len; i++) value[i] = chars[0 | Math.random() * radix];

  return value.join('');
}

export function toThousNumber(num: number) {
    return num.toString().replace(/\d{1,3}(?=(\d{3})+$)/g, function(s) {
      return s + ','
    })
}
